package com.jming.jike.util.sensitivity;

import java.util.function.Function;

/**
 * @author jinming.zhang
 * @version 0.0.1
 * @date 2022/05/31
 */
public enum SensitiveStrategy {

    /**
     * 用户名脱敏
     */
    USERNAME(s -> s.replaceAll("\\S*(\\S)", "*$1")),

    /**
     * 身份证脱敏
     */
    ID_CARD(s -> s.replaceAll("(\\d{4})\\d*(\\w{4})", "$1****$2")),

    /**
     * 手机号脱敏
     */
    PHONE(s -> s.replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2")),

    /**
     * 地址脱敏
     */
    ADDRESS(s -> s.replaceAll("(\\S{3})\\S*", "$1********"))
    ;

    private final Function<String, String> desensitize;

    SensitiveStrategy(Function<String, String> desensitize) {
        this.desensitize = desensitize;
    }

    public Function<String, String> getDesensitize() {
        return desensitize;
    }

}
